package com.taven.app.javabase.thread.base.syncerror;

public class Account
{
	// 封装账户编号、账户余额两个Field
	private String accountNo;
	private double balance;

	public Account() {}

	// 构造器
	public Account(String accountNo, double balance)
	{
		this.accountNo = accountNo;
		this.balance = balance;
	}

	// 此处省略了accountNo和balance两个Field的setter和getter方法

	// accountNo的setter和getter方法
	public void setAccountNo(String accountNo)
	{
		this.accountNo = accountNo;
	}

	public String getAccountNo()
	{
		return this.accountNo;
	}

	// balance的setter和getter方法
	public void setBalance(double balance)
	{
		this.balance = balance;
	}

	public double getBalance()
	{
		return this.balance;
	}

	// 下面两个方法根据accountNo来重写hashCode()和equals()方法
	public int hashCode()
	{
		return accountNo.hashCode();
	}

	public boolean equals(Object obj)
	{
		if (this == obj)
			return true;
		if (obj != null
				&& obj.getClass() == Account.class)
		{
			Account target = (Account) obj;
			return target.getAccountNo().equals(accountNo);
		}
		return false;
	}
}
